<?php
/**
 * Created by PhpStorm.
 * User: 魏爷
 * Date: 2016/5/31
 * Time: 15:21
 */

namespace Admin\Model;


class BuyBookModel extends BaseModel
{
    // 数据表名（不包含表前缀）
    protected $tableName        =   'buybook';

    /**
     * 根据条件获得表信息
     * @param String $book_name 图书名称
     * @param String $buy_type 图书类型
     * @return array()
    **/
    public function getBookByIdBuyInfo($book_name,$buy_type){
        $where=array();
        if(!empty($book_name)){
            $where['book_name']=array('LIKE',"%{$book_name}%");
        }
        if(!empty($buy_type)){
            $where['buy_type']=$buy_type;
        }
        $where['book_status']=2;
        return $this->where($where)->order('buybook_id DESC')->select();
    }
    /**
     * 获取订单表所有信息
     * @return array()
    **/
    public function getBookBuyInfo(){
        return $this->where("book_status=1")->order('buybook_id DESC')->select();
    }
    /**
     * 订单完成
     * @param Integer $buybook_id 订单ID
     * @return boolean
    **/
    public function tradeStatus($buybook_id){
        $res=$this->where("buybook_id=$buybook_id")->setField('book_status',3);
        return $res==false?false:true;
    }
    /**
     * 订单确认
     * @param Integer $buybook_id 订单ID
     * @return boolean
    **/
    public function tradeInfoStatus($buybook_id){
        $res=$this->where("buybook_id=$buybook_id")->setField('book_status',2);
        return $res==false?false:true;
    }

}